namespace Crux.Core.Query;
/// <summary>
///
/// </summary>
public record QueryResult<T>
    : IQueryExecuteResult<T>
{
    /// <summary>
    ///
    /// </summary>
    public T Data { get; init; }
    /// <summary>
    ///
    /// </summary>
    public bool Success { get; init; }
    /// <summary>
    ///
    /// </summary>
    public string? Message { get; init; }
    /// <summary>
    ///
    /// </summary>
    /// <param name="data"></param>
    /// <param name="success"></param>
    /// <param name="message"></param>
    /// <exception cref="ArgumentNullException"></exception>
    private QueryResult(
        T data,
        bool success = true,
        string? message = null)
    {
        if (!success && string.IsNullOrEmpty(message)) throw new ArgumentNullException("message must be not null");
        this.Data = data;
        this.Success = success;
        this.Message = message;
    }
    /// <summary>
    ///
    /// </summary>
    public static QueryResult<T> Successed(T data) => new QueryResult<T>(data);
    /// <summary>
    ///
    /// </summary>
    public static QueryResult<T> Failed(T data, string message) => new QueryResult<T>(data, success: false, message: message);
    /// <summary>
    ///
    /// </summary>
    public void Deconstruct(out bool success, out string? message, out T data)
    {
        success = Success;
        message = Message;
        data = Data;
    }
    /// <summary>
    ///
    /// </summary>
    public void Deconstruct(out bool success, out T data)
    {
        success = Success;
        data = Data;
    }
    /// <summary>
    ///
    /// </summary>
    public void Deconstruct(out bool success)
    {
        success = Success;
    }
}
